//
//  UIBarButtonItem+ZBarButtonItem.swift
//  swift-weibo
//
//  Created by zero on 17/3/19.
//  Copyright © 2017年 zero. All rights reserved.
//

import UIKit


extension UIBarButtonItem{
    
    convenience init(title:String? = nil, imageName:String, target: Any?, action: Selector?) {
        
        let btn = UIButton()
        
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.black, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        btn.setImage(UIImage(named: imageName), for: .normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        
        if let t = target, let a = action {
            
            btn.addTarget(t, action: a, for: .touchUpInside)
        }
        
        btn.sizeToFit()
        
        self.init()
        
        self.customView = btn
    }
    
}
